package com.yangsir.mysite.controller;

import com.yangsir.mysite.Dto.CommentDto;
import com.yangsir.mysite.common.R;
import com.yangsir.mysite.pojo.Comment;
import com.yangsir.mysite.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * java 8
 */
@CrossOrigin
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping("/save")
    public R<String> saveComment(@RequestBody Comment comment) {
        if (comment == null) {
            return R.error("评论不能为空");
        }
        return commentService.saveComment(comment);
    }

    @GetMapping("/getComment")
    public R<List<CommentDto>> getComment(Long id) {
        if (id == null) {
            return R.error("关键信息缺失");
        }
        return commentService.getComment(id);
    }
}
